package clusteringAlg;



import org.opencv.core.Size;

/**
 * @author Dominik
 *
 */
public abstract class SamplesSelector implements SampleSelectorInterface{
	
	Person person;						// jednotlive vzorky(fotografie)
	int nClusters=0;								// pocet vyslednych snimkov
	protected int iterations = 0;
		
	/**
	 * @param person
	 * @param nClusters
	 * @param iterations
	 */
	public SamplesSelector(Person person, int nClusters, int iterations) {
		super();
		this.person = person;
		this.nClusters = nClusters;
		this.iterations = iterations;
	}

	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public int getnClusters() {
		return nClusters;
	}

	public void setnClusters(int nOutputSamples) {
		this.nClusters = nOutputSamples;
	}
	
	public int getIterations() {
		return iterations;
	}

	public void setIterations(int iterations) {
		this.iterations = iterations;
	}

	public SamplesSelector() {
		super();
		person = new Person();
	}
	
	public void printAllSamples(){
		
		for (Sample m: person.getSamples()){
			System.out.println("Person "+ this.person.getId() +" and image" + m);
			System.out.println( m.getImage().get(0,0)[0] );
		}
	}	
	
	public int GetSampleCount(){
		return this.person.GetSampleCount();
	}
	
	public Size GetSampleSize(){
		return this.person.GetSampleSize();
	}
	
	public int GetSampleType(){
		return this.person.GetSampleType();
	}
	
	/*
	 * funkcia , ktora vyr=ata vzdialenost dvoch vektorov
	 * */
	double EukclideanDistance(double[] array1, double[] array2){
		
		double dist = 0.0;
		
		if (array1.length != array2.length)
			return -1;
		
	    for(int i = 0; i < array1.length; i++)
	    {
	    	dist = dist + Math.pow((array1[i]) - (array2[i]), 2);
	    }
		
		return Math.sqrt(dist);
	}	
	
	/*
	 * ScaleData:
	 * 
	 * - vsetky fotografie ulozi z Mat objektu do double[] pola
	 * 
	 * */
	
	void ScaleData(double minVal, double maxVal){
		
		if (this.person != null){
			return;
		}
					
		for (Sample s: this.person.getSamples()){
			s.ScaleImage(minVal, maxVal);
		}
	}	
}
